#include "LyInvokedObj.h"

LyInvokedObj::LyInvokedObj(int lineNumber,DIVA_VM* vm){
	this->_lineNum = lineNumber;
	this->_vm = vm;
	this->_evt = NULL;
}

void LyInvokedObj::recover(){
	//ChangeObject理論上只牽涉到位置的變化
	if(this->_evt != NULL){
		if(this->_evt->getName() == "Position_Change"){
			Ogre::Vector3 currentpos = Ogre::StringConverter::parseVector3(this->_evt->getCurrentValue());
			if(this->_vm->get_visible()){
				this->_vm->setPosition(currentpos);
			}
		}
		else{
			//should not be wop_change or position_change
			assert(false);
		}
		this->_evt->recover();
	}
}

void LyInvokedObj::render(float timeSinceLastFrame){
	if(this->_evt != NULL){
		if(!this->_evt->checkBounding()){
			this->_evt->writePastValueToVariation();
		}
		if(this->_evt->getName() == "Position_Change"){
			Ogre::Vector3 pos = Ogre::StringConverter::parseVector3(this->_evt->getVariation());
			this->_vm->setPosition(pos);
		}
		else{
			assert(false);
		}
	}
}